﻿using System;
using System.Linq;
using System.Web;

namespace Web.Infrastructure.Extensions
{
    public static class HttpContextExtensions
    {
        public static string GetIpAddress(this HttpContextBase httpContext)
        {
            String ip = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
            ip = string.IsNullOrEmpty(ip) ? HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"] : ip.Split(',').Last().Trim(); ;

            return ip;
        }
    }
}